﻿using UnityEngine;
using System.Collections;

public class SecurityCamera : MonoBehaviour, IHackeableObject {

	SpriteRenderer cameraSprite;

	float maxAngle = 1.3f;
	float minAngle = 0;
	float currentAngle;
	int rotationDirection = 1;
	bool allowCameraRot;

	Transform maxRotLimit;
	Transform minRotLimit;

	void Awake() {
		Transform cameraBody = this.transform.Find("cameraBody");
		cameraSprite = (SpriteRenderer)cameraBody.GetComponent(typeof(SpriteRenderer));
		minAngle = -maxAngle;
		allowCameraRot = true;
	}

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if (!allowCameraRot) {
			return;
		}
		currentAngle += Time.deltaTime*rotationDirection;
		cameraSprite.transform.Rotate(0, 0, currentAngle);

		if (currentAngle >= maxAngle) {
			rotationDirection = -1;
			currentAngle = 0;
		}
		else if (currentAngle <= minAngle) {
			rotationDirection = 1;
			currentAngle = 0;
		}
	}

	public void Hack() {
		Debug.Log("SOY UNA CAMARA Y ME HACKEARON!");
		allowCameraRot = false;

	}

}
